Skip to content

feat: add safe configurable iOS HTTP logging - #223

Merged
mohamede1945 merged 2 commits into
mainfrom
afifi/ios-http-debug-logging
Jul 30, 2026
Merged

feat: add safe configurable iOS HTTP logging#223
mohamede1945 merged 2 commits into
mainfrom
afifi/ios-http-debug-logging

Conversation

@mohamede1945

Copy link
Copy Markdown
Collaborator

Summary

  • Configure Darwin Ktor logging through MOBILE_SYNC_HTTP_LOG_LEVEL (ALL, BODY, HEADERS, INFO, or NONE).
  • Emit Ktor messages to standard output so Xcode and Simulator log capture receive request and response bodies.
  • Redact authorization, cookie, and x-auth-token headers.
  • Scrub OAuth access tokens, refresh tokens, ID tokens, authorization codes, and PKCE verifiers from verbose bodies.
  • Add regression coverage for OAuth log sanitization.

Why

KMP API traffic was difficult to inspect from the iOS example app because the prior logger did not reach the captured console. Enabling verbose OAuth logging also exposed credentials, so debugging must remain safe by default.

Validation

  • ./gradlew :auth:allTests
  • ./gradlew :syncengine:allTests
  • Built the debug XCFramework and consumed it through mobile-sync-spm in the QuranEngine example app.
  • Captured a live sync request/response and verified credential redaction.

Route Ktor logs through Kermit, support runtime log levels, and redact authentication and cookie headers.
Route iOS Ktor output to the captured console and sanitize authentication headers.

Redact OAuth tokens, authorization codes, and PKCE verifiers from verbose request and response bodies.
level = if (config.environment.enableVerboseLogging) LogLevel.ALL else LogLevel.NONE
sanitizeHeader { header ->
header.equals(HttpHeaders.Authorization, ignoreCase = true) ||
header.equals(HttpHeaders.Cookie, ignoreCase = true) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever send a cookie header?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let codex search the code and couldn't find any uses, seems like a defensive mechanism. Here is what it said:

Not currently. This client doesn’t configure cookie storage or set a Cookie header. The browser-based OAuth flow may use cookies independently, but those requests don’t pass through this logger. I included Cookie and Set-Cookie as defense-in-depth in case the server returns one or cookie handling is added later.

@mohamede1945
mohamede1945 marked this pull request as ready for review July 29, 2026 23:37
@mohamede1945
mohamede1945 merged commit c9a7e60 into main Jul 30, 2026
1 check passed
@mohamede1945
mohamede1945 deleted the afifi/ios-http-debug-logging branch July 30, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants